.\" $Id$
.TH LAT_MEM_RD 8 "$Date$" "(c)1994 Larry McVoy" "LMBENCH"
.SH NAME
lat_mem_rd \- memory read latency benchmark
.SH SYNOPSIS
.B lat_mem_rd 
[
.I "-P <parallelism>"
]
[
.I "-W <warmups>"
]
[
.I "-N <repetitions>"
]
.I "size_in_megabytes"
.I "stride"
[
.I "stride stride..."
]
.SH DESCRIPTION
.B lat_mem_rd
measures memory read latency for varying memory sizes and strides.  The
results are reported in nanoseconds per load and have been verified
accurate to within a few nanoseconds on an SGI Indy.
.LP
The
entire memory hierarchy is measured, including onboard cache latency
and size, external cache latency and size, main memory latency, and TLB
miss latency.
.LP
Only data accesses are measured; the instruction cache is not measured.
.LP
The benchmark runs as two nested loops.  The outer loop is the stride size.
The inner loop is the array size.  For each array size, the benchmark
creates a ring of pointers that point backward one stride.  Traversing the
array is done by
.sp
.ft CB
	p = (char **)*p;
.ft
.sp
in a for loop (the over head of the for loop is not significant; the loop is 
an unrolled loop 100 loads long).  
.LP
The size of the array varies from 512 bytes to (typically) eight megabytes.
For the small sizes, the cache will have an effect, and the loads will be
much faster.  This becomes much more apparent when the data is plotted.
.LP
Since this benchmark uses fixed-stride offsets in the pointer chain,
it may be vulnerable to smart, stride-sensitive cache prefetching
policies.  Older machines were typically able to prefetch for
sequential access patterns, and some were able to prefetch for strided
forward access patterns, but only a few could prefetch for backward
strided patterns.  These capabilities are becoming more widespread
in newer processors.
.SH OUTPUT
Output format is intended as input to \fBxgraph\fP or some similar program
(we use a perl script that produces pic input).
There is a set of data produced for each stride.  The data set title
is the stride size and the data points are the array size in megabytes 
(floating point value) and the load latency over all points in that array.
.SH "INTERPRETING THE OUTPUT"
The output is best examined in a graph where you typically get a graph
that has four plateaus.  The graph should plotted in log base 2 of the
array size on the X axis and the latency on the Y axis.  Each stride
is then plotted as a curve.  The plateaus that appear correspond to 
the onboard cache (if present), external cache (if present), main
memory latency, and TLB miss latency.
.LP
As a rough guide, you may be able to extract the latencies of the
various parts as follows, but you should really look at the graphs,
since these rules of thumb do not always work (some systems do not
have onboard cache, for example).
.IP "onboard cache" 16
Try stride of 128 and array size of .00098.
.IP "external cache" 
Try stride of 128 and array size of .125.
.IP "main memory"
Try stride of 128 and array size of 8.
.IP "TLB miss"
Try the largest stride and the largest array.
.SH BUGS
This program is dependent on the correct operation of
.BR mhz (8).
If you are getting numbers that seem off, check that 
.BR mhz (8)
is giving you a clock rate that you believe.
.SH ACKNOWLEDGEMENT
Funding for the development of
this tool was provided by Sun Microsystems Computer Corporation.
.SH "SEE ALSO"
lmbench(8), tlb(8), cache(8), line(8).
.SH "AUTHOR"
Carl Staelin and Larry McVoy
.PP
Comments, suggestions, and bug reports are always welcome.
